package com.hskn.hss.module.elementtotal.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.domain.BaseEntity;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.exception.ProgramTerminationException;
import com.hskn.hss.module.elementtotal.service.ElementTotalService;
import com.hskn.hss.module.elementtotal.to.DTUByFacIdTO;
import com.hskn.hss.module.elementtotal.vo.*;
import com.hskn.hss.module.tlcar.entity.TlCar;
import com.hskn.hss.module.tlcar.vo.CarJobType;
import com.hskn.hss.module.tlempsalary.entity.TlEmpSalary;
import com.hskn.hss.module.tlempsalary.to.TlEmpSalaryDetailTO;
import com.hskn.hss.utils.LocationUtils;
import com.hskn.hss.utils.Tools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-15
 */
@Api(tags = {"-element_total"}, description = "一张网各类元素")
@Slf4j
@RestController
@RequestMapping("/hss/elementtotal")
public class ElementTotalController {
    @Autowired
    ElementTotalService elementTotalService;
    @Autowired
    LocationUtils locationUtil;

    @RequestMapping(value = "getTotalNum", method = RequestMethod.POST)
    public AjaxResult<Object> getTotalNum(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getTotalNum(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getNumByType", method = RequestMethod.POST)
    public AjaxResult<Object> getNumByType(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getNumByType(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getAddrForMap", method = RequestMethod.POST)
    public AjaxResult<Object> getAddrForMap(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            if (null == params) {
                params = new JSONObject();
            }
            return AjaxResult.success(elementTotalService.getAddrForMap(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getAddrForMapByType", method = RequestMethod.POST)
    public AjaxResult<Object> getAddrForMapByType(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getAddrForMapByType(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getTrashCleanMap", method = RequestMethod.POST)
    public AjaxResult<Object> getTrashCleanMap(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getTrashCleanMap(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getToiletNumMap", method = RequestMethod.POST)
    public AjaxResult<Object> getToiletNumMap(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getToiletNumMap(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getToiletDetailMap", method = RequestMethod.POST)
    public AjaxResult<Object> getToiletDetailMap(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getToiletDetailMap(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getToiletStatusNumMap", method = RequestMethod.POST)
    public AjaxResult<Object> getToiletStatusNumMap(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getToiletStatusNumMap(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getGreenAreaMap", method = RequestMethod.POST)
    public AjaxResult<Object> getGreenAreaMap(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getGreenAreaMap(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getParkDetailMap", method = RequestMethod.POST)
    public AjaxResult<Object> getParkDetailMap(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getParkDetailMap(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getAciTreeDetailMap", method = RequestMethod.POST)
    public AjaxResult<Object> getAciTreeDetailMap(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getAciTreeDetailMap(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getGreenStatusMap", method = RequestMethod.POST)
    public AjaxResult<Object> getGreenStatusMap(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getGreenStatusMap(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getSensorStatusMap", method = RequestMethod.POST)
    public AjaxResult<Object> getSensorStatusMap(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getSensorStatusMap(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getVideoMap", method = RequestMethod.POST)
    public AjaxResult<Object> getVideoMap(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getVideoMap(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getCarDetailByid", method = RequestMethod.POST)
    public AjaxResult<Object> getCarDetailByid(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getCarDetailByid(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getFaclAlarmNum", method = RequestMethod.POST)
    public AjaxResult<Object> getFaclAlarmNum(HttpServletRequest request) {
        try {
            return AjaxResult.success(elementTotalService.getFaclAlarmNum());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }


    @RequestMapping(value = "getEmpLocation", method = RequestMethod.POST)
    public AjaxResult<Object> getEmpLocation(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getEmpLocation(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getCarLocation", method = RequestMethod.POST)
    public AjaxResult<Object> getCarLocation(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getCarLocation(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @ApiOperation(value = "获取车辆作业类型", notes = "作业类型数据")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = TlEmpSalary.class)})
    @RequestMapping(value = "getCarJobType", method = RequestMethod.POST)
    public AjaxResult<Object> getCarJobType(@RequestBody @Validated TlCar tlCar) {
        CarJobType carJobType;
        try {
            carJobType = elementTotalService.getCarJobType(tlCar);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
        return AjaxResult.success(carJobType);

    }

    @RequestMapping(value = "getSearchList", method = RequestMethod.POST)
    public AjaxResult<Object> getSearchList(@RequestBody @Validated EmpAndCarAndFaclTo empAndCarAndFaclTo) {
        try {
            return AjaxResult.success(elementTotalService.getSearchList(empAndCarAndFaclTo));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }


    @RequestMapping(value = "getHummanTotal", method = RequestMethod.POST)
    public AjaxResult<Object> getHummanTotal(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getHummanTotal(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @ApiOperation(value = "获取DTU设备数据", notes = "获取DTU设备数据")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = DTUDataMap.class),
            @ApiResponse(code = 408, message = "暂无设备")})
    @RequestMapping(value = "getDtuByFaclId", method = RequestMethod.POST)
    public AjaxResult<Object> getDtuByFaclId(HttpServletRequest request, @Validated @RequestBody DTUByFacIdTO dtuByFacIdTO) {
        try {
            return AjaxResult.success(elementTotalService.getDtuByFaclId(dtuByFacIdTO.getFaclid()));
        } catch (ProgramTerminationException em) {
            return AjaxResult.fail("暂无设备", 408);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @ApiOperation(value = "获取井盖设备数据", notes = "获取DTU设备数据")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = DTUDataMap.class),
            @ApiResponse(code = 408, message = "暂无设备")})
    @RequestMapping(value = "getManholeCoverByFaclId", method = RequestMethod.POST)
    public AjaxResult<Object> getManholeCoverByFaclId(HttpServletRequest request, @Validated @RequestBody DTUByFacIdTO dtuByFacIdTO) {
        try {
            return AjaxResult.success(elementTotalService.getManholeCoverByFaclId(dtuByFacIdTO.getFaclid()));
        } catch (ProgramTerminationException em) {
            return AjaxResult.fail("暂无设备", 408);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getVideoMapList", method = RequestMethod.POST)
    public AjaxResult<Object> getVideoMapList(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            BaseEntity entity = new BaseEntity();
            JSONObject json = elementTotalService.getVideoMapList(entity, params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getCarMoveStay", method = RequestMethod.POST)
    public AjaxResult<Object> getCarMoveStay(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getCarMoveStay(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getPersonMoveStay", method = RequestMethod.POST)
    public AjaxResult<Object> getPersonMoveStay(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getPersonMoveStay(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

    @RequestMapping(value = "getTrashTree", method = RequestMethod.POST)
    public AjaxResult<Object> getTrashTree(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getTrashTree(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getEmpSearchList", method = RequestMethod.POST)
    public AjaxResult<Object> getEmpSearchList(@RequestBody @Validated EmpAndCarAndFaclTo empAndCarAndFaclTo) {
        try {
            return AjaxResult.success(elementTotalService.getEmpSearchList(empAndCarAndFaclTo));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getCarSearchList", method = RequestMethod.POST)
    public AjaxResult<Object> getCarSearchList(@RequestBody @Validated EmpAndCarAndFaclTo empAndCarAndFaclTo) {
        try {
            return AjaxResult.success(elementTotalService.getCarSearchList(empAndCarAndFaclTo));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getFaclSearchList", method = RequestMethod.POST)
    public AjaxResult<Object> getFaclSearchList(@RequestBody @Validated EmpAndCarAndFaclTo empAndCarAndFaclTo) {
        try {
            return AjaxResult.success(elementTotalService.getFaclSearchList(empAndCarAndFaclTo));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getWorkTypeNumber", method = RequestMethod.POST)
    public AjaxResult<Object> getWorkTypeNumber(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getWorkTypeNumber(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getCarTypeNumber", method = RequestMethod.POST)
    public AjaxResult<Object> getCarTypeNumber(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.getCarTypeNumber(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getElementsList", method = RequestMethod.POST)
    public AjaxResult<Object> getElementsList(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(elementTotalService.elementsList(params));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getElementsListByApp", method = RequestMethod.POST)
    public AjaxResult<Object> getElementsListByApp() {
        try {
            return AjaxResult.success(elementTotalService.getElementsListByApp());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
    }
}

